<template>
  <d2-container>
    <el-input type="textarea" v-model="contentDetail.content" rows="9"></el-input>
    <el-divider></el-divider>
    <el-button type="primary" size="small" @click="handleSave">保存</el-button>
  </d2-container>
</template>

<script>
import { queryDetailByContentId, saveOrEdit4Detail } from "@api/cms.content";
import { Message, MessageBox } from "element-ui";

export default {
  data() {
    return {
      contentDetail: {
        id: null,
        contentId: null,
        content: null,
      }
    };
  },

  created: function() {
    let contentId = this.$route.query.id;
    console.log(contentId);

    queryDetailByContentId(contentId)
      .then(res => {
        console.log(res);
        if(res == "") {
          this.contentDetail.contentId = contentId;
          this.contentDetail.content = "";
        }
        else
          this.contentDetail = res;
      })
      .catch(err => {
        console.log("err: ", err);
      });
  },

  methods: {
    handleSave() {
      console.log(666);

      saveOrEdit4Detail(this.contentDetail)
        .then(res => {
          console.log(res);
          Message({
            type: "success",
            duration: 1500,
            message: "操作成功"
          });
          
        })
        .catch(err => {
          console.log("err: ", err);
        });
    }
  }
};
</script>
